<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="admin-clients" mode="admin-client-edit">
	<div class="calendar-head">
		<h2>Edit Client</h2>
	</div>
	
	<div class="admin-message">
		<xsl:if test="/data/events/admin-clients/@result = 'error'">
			<h4>
				<xsl:value-of select="/data/events/admin-clients/@result"/>
				<xsl:text>. The following errors were encountered when attempting to save this client:</xsl:text>
				<xsl:value-of select="/data/events/admin-clients/filter[@name = 'send-email']"/>
			</h4>
			
			<xsl:if test="/data/events/admin-clients/first-name/@type = 'missing'">
				<p>
					<strong>First Name</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
			<xsl:if test="/data/events/admin-clients/last-name/@type = 'missing'">
				<p>
					<strong>Last Name</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
			<xsl:if test="/data/events/admin-clients/email-address/@type = 'missing'">
				<p>
					<strong>Email Address (client's username)</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
			<xsl:if test="/data/events/admin-clients/client-password/@type = 'missing'">
				<p>
					<strong>Client Password</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
		</xsl:if>
		<xsl:if test="/data/events/admin-clients/@result = 'success'">
			<h4>
				<xsl:value-of select="/data/events/admin-clients/@result"/>
				<xsl:text>. </xsl:text>
				<xsl:value-of select="/data/events/admin-clients/message"/>
			</h4>
		</xsl:if>
	</div>
	
	<form method="post" action="" enctype="multipart/form-data">
		<input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
		<label>First Name
			<input name="fields[first-name]" type="text" value="{entry[@id = $entry-id]/first-name}" />
		</label>
		<label>Last Name
			<input name="fields[last-name]" type="text" value="{entry[@id = $entry-id]/last-name}" />
		</label>
		<label>Email Address (client's username)
			<input name="fields[email-address]" type="text" value="{entry[@id = $entry-id]/email-address}" />
		</label>
		<label>Client Password
			<input name="fields[client-password]" type="text" value="{entry[@id = $entry-id]/client-password}" />
		</label>
		<label>Client Home Phone
			<input name="fields[client-home-phone]" type="text" value="{entry[@id = $entry-id]/client-home-phone}" />
		</label>
		<label>Client Mobile Phone
			<input name="fields[client-mobile-phone]" type="text" value="{entry[@id = $entry-id]/client-mobile-phone}" />
		</label>
		<label>Client Status
			<select name="fields[client-status]">
				<xsl:choose>
					<xsl:when test="entry[@id = $entry-id]/client-status/item/@handle = 'active'">
						<option value="Active" selected="selected">Active</option>
					</xsl:when>
					<xsl:otherwise>
						<option value="Active">Active</option>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:choose>
					<xsl:when test="entry[@id = $entry-id]/client-status/item/@handle = 'suspended'">
						<option value="Suspended" selected="selected">Suspended</option>
					</xsl:when>
					<xsl:otherwise>
						<option value="Suspended">Suspended</option>
					</xsl:otherwise>
				</xsl:choose>
					<xsl:choose>
						<xsl:when test="entry[@id = $entry-id]/client-status/item/@handle = 'closed'">
							<option value="Closed" selected="selected">Closed</option>
						</xsl:when>
						<xsl:otherwise>
							<option value="Closed">Closed</option>
						</xsl:otherwise>
					</xsl:choose>
				
			</select>
		</label>
		<label class="inline">Is this client an Administrator?
			<select name="fields[administrator]">
				<xsl:choose>
					<xsl:when test="entry[@id = $entry-id]/administrator = 'No'">
						<option value="no" selected="selected">No</option>
					</xsl:when>
					<xsl:otherwise>
						<option value="no">No</option>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:choose>
					<xsl:when test="entry[@id = $entry-id]/administrator = 'Yes'">
						<option value="yes" selected="selected">Yes</option>
					</xsl:when>
					<xsl:otherwise>
						<option value="yes">Yes</option>
					</xsl:otherwise>
				</xsl:choose>
			</select>
		</label>
		<input name="id" type="hidden" value="{entry[@id = $entry-id]/@id}" />
		<input name="action[admin-client-delete]" type="submit" value="Delete Client" />
		<input name="action[admin-clients]" type="submit" value="Save Changes" />
	</form>

</xsl:template>




<xsl:template match="admin-clients" mode="admin-client-new">
	<!--xsl:param name="" select=""/-->
	
	<div class="calendar-head">
		<h2>Create a Client</h2>
	</div>
			
	<div class="admin-message">
		<xsl:if test="/data/events/admin-clients/@result = 'error'">
			<h4>
				<xsl:value-of select="/data/events/admin-clients/@result"/>
				<xsl:text>. The following errors were encountered when attempting to save this course:</xsl:text>
				<xsl:value-of select="/data/events/admin-clients/filter[@name = 'send-email']"/>
			</h4>
			
			<xsl:if test="/data/events/admin-clients/first-name/@type = 'missing'">
				<p>
					<strong>First Name</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
			<xsl:if test="/data/events/admin-clients/last-name/@type = 'missing'">
				<p>
					<strong>Last Name</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
			<xsl:if test="/data/events/admin-clients/email-address/@type = 'missing'">
				<p>
					<strong>Email Address (client's username)</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
			<xsl:if test="/data/events/admin-clients/client-password/@type = 'missing'">
				<p>
					<strong>Client Password</strong>
					<xsl:text> is a required field.</xsl:text>
				</p>
			</xsl:if>
		</xsl:if>
		<xsl:if test="/data/events/admin-clients/@result = 'success'">
			<h4>
				<xsl:value-of select="/data/events/admin-clients/@result"/>
				<xsl:text>. </xsl:text>
				<xsl:value-of select="/data/events/admin-clients/message"/>
			</h4>
		</xsl:if>
	</div>
	
	<form method="post" action="" enctype="multipart/form-data">
		<input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
		<label>First Name
			<input name="fields[first-name]" type="text" />
		</label>
		<label>Last Name
			<input name="fields[last-name]" type="text" />
		</label>
		<label>Email Address (client's username)
			<input name="fields[email-address]" type="text" />
		</label>
		<label>Client Password
			<input name="fields[client-password]" type="text" />
		</label>
		<label>Client Home Phone
			<input name="fields[client-home-phone]" type="text" />
		</label>
		<label>Client Mobile Phone
			<input name="fields[client-mobile-phone]" type="text" />
		</label>
		<label>Client Status
			<select name="fields[client-status]">
				<option value="Active">Active</option>
				<option value="Suspended">Suspended</option>
				<option value="Closed">Closed</option>
			</select>
		</label>
		<label class="inline">Is this client an Administrator?
			<input name="fields[administrator]" type="checkbox" />
		</label>
		<input name="action[admin-clients]" type="submit" value="Create Client" />
	</form>
	<!--xsl:apply-templates select="entry[normalize-space(instructor/item/@handle) = normalize-space($instructor-username)]" mode="new-client"/-->
</xsl:template>




<!--
	called from 'get-admin-menu.xsl'
-->
<xsl:template match="admin-clients" mode="admin-clients-list">
	<select id="admin_edit_client">
		<option value="Edit a client">select a client</option>
		<option disabled="disabled" value="">--------------</option>
		<xsl:apply-templates select="entry[administrator = 'No']" mode="list"/>
	</select>
</xsl:template>

<xsl:template match="admin-clients/entry" mode="list">
	<xsl:choose>
		<xsl:when test="@id = $entry-id and $current-page = 'admin-clients'">
			<option value="{@id}" selected="selected">
				<xsl:value-of select="last-name"/>
				<xsl:text>, </xsl:text>
				<xsl:value-of select="first-name"/>
			</option>
		</xsl:when>
		<xsl:otherwise>
			<option value="{@id}">
				<xsl:value-of select="last-name"/>
				<xsl:text>, </xsl:text>
				<xsl:value-of select="first-name"/>
			</option>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>